<?php

namespace app\admin\model;

use think\Model;

class Admin extends Model
{
    public function checkPassword($password)
    {
        if ($this->password && $this->password == $this->encrypt($password)) {
            return true;
        }
        return false;
    }

    public function setPassword($password)
    {
        $this->safe_code = $this->safeCode();
        $this->password = $this->encrypt($password);
        if ($this->save()) {
            return true;
        }
        return false;
    }

    public function encrypt($password)
    {
        return md5(md5($password) . $this->safe_code);
    }

    public function safeCode()
    {
        return substr(md5(time()), rand(0, 28), 4);
    }
}